<extend name="Base/common" />
<block name="body">
<div class="page-container">
  <div class="cl pd-5 bg-1 bk-gray mt-20">
    <a href="{:U('/admin/agent/agent_add')}" class="btn btn-success"><i class="Hui-iconfont Hui-iconfont-add"></i> 添加代理</a>
  </div>
  <input type="hidden" name="page" id="page" value="{$page}"/>
  <table class="table table-border table-bordered table-bg mt-20">
    <thead>
      <tr>
        <th>ID</th>
        <th>等级</th>
        <th>姓名</th>
        <th>手机</th>
        <th>邮箱</th>
        <th>QQ</th>
        <th>微信</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
    <foreach name="agent_list" item="item">
    <tr>
      <td>{$item['id']}</td>
      <td>{$item['lv']}</td>
      <td><a class="c-primary" href="{:U('/admin/agent/agent_info', array('id' => $item['id']))}">{$item['username']}</a></td>
      <td>{$item['mobile']}</td>
      <td>{$item['email']}</td>
      <td>{$item['qq']}</td>
      <td>{$item['wx']}</td>
      <td>
        <a class="c-primary" href="{:U('/admin/agent/agent_edit', array('id' => $item['id']))}">编辑</a> 
        <a class="c-error account-btn" href="javascript:;" data-id="{$item['id']}">删除</a> 
      </td>
    </tr>
    </foreach>
    </tbody>
  </table>
  <div id="pager" style="margin-top:20px;"></div>
</div>
<script>
$('.account-btn').on('click', function(){
  var id = $(this).data('id');
  layer.confirm('确认要删除吗？',function(index){
    $.ajax({
      type: 'POST',
      url: "{:U('/admin/agent/agent_del')}",
      dataType: 'json',
      data: {'id': id},
      success: function(data){
        window.location.reload()
      },
      error:function(data) {
        console.log(data.msg);
      },
    });
  });
});
$(function(){
  $("[data-toggle='popover']").popover();
  $("[data-toggle='tooltip']").tooltip();
  laypage({
    cont: 'pager',
    skip: true,
    pages: {$page_count},
    curr: {$page},
    jump: function(e){
      var page = $('#page').val();
      if (page != e.curr) {
        window.location.href = "/admin/agent/agent_list?page=" + e.curr;
      }
    }
  });
});
</script>
</block>
